<!DOCTYPE html>
<html lang="${LANG}" class="dark">

<head>
    <meta charset="UTF-8">
    <title>QBT_TR(Add Torrent Links)QBT_TR[CONTEXT=downloadFromURL]</title>
    <link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
    <link rel="stylesheet" href="css/Window.css?v=${CACHEID}" type="text/css">
    <script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
    <script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
    <script defer src="scripts/download.js?v=${CACHEID}"></script>
    <script defer src="scripts/pathAutofill.js?v=${CACHEID}"></script>
    <script>
        "use strict";

        window.addEventListener("DOMContentLoaded", (event) => {
            window.addEventListener("keydown", (event) => {
                switch (event.key) {
                    case "Escape":
                        event.preventDefault();
                        window.parent.qBittorrent.Client.closeFrameWindow(window);
                        break;
                }
            });

            const encodedUrls = new URLSearchParams(window.location.search).get("urls");
            if (encodedUrls !== null) {
                const urls = encodedUrls.split("|").map(decodeURIComponent);
                if (urls.length > 0)
                    document.getElementById("urls").value = urls.join("\n");
            }

            let submitted = false;

            document.getElementById("downloadForm").addEventListener("submit", (event) => {
                document.getElementById("startTorrentHidden").value = document.getElementById("startTorrent").checked ? "false" : "true";

                document.getElementById("dlLimitHidden").value = Number(document.getElementById("dlLimitText").value) * 1024;
                document.getElementById("upLimitHidden").value = Number(document.getElementById("upLimitText").value) * 1024;

                document.getElementById("download_spinner").style.display = "block";
                submitted = true;
            });

            document.getElementById("download_frame").addEventListener("load", (event) => {
                if (submitted)
                    window.parent.qBittorrent.Client.closeFrameWindow(window);
            });

            window.qBittorrent.pathAutofill.attachPathAutofill();
        });
    </script>
</head>

<body>
    <iframe id="download_frame" name="download_frame" class="invisible" title="" src="about:blank"></iframe>
    <form action="api/v2/torrents/add" enctype="multipart/form-data" method="post" id="downloadForm" style="text-align: center;" target="download_frame" autocorrect="off" autocapitalize="none">
        <div style="text-align: center;">
            <br>
            <h2><label for="urls">QBT_TR(Add torrent links)QBT_TR[CONTEXT=AddNewTorrentDialog]</label></h2>
            <textarea id="urls" rows="10" name="urls"></textarea>
            <p><i>QBT_TR(One link per line (HTTP links, Magnet links and info-hashes are supported))QBT_TR[CONTEXT=AddNewTorrentDialog]</i></p>
            <fieldset class="settings" style="border: 0; text-align: left; margin-top: 6px;">
                <legend>QBT_TR(Torrent options)QBT_TR[CONTEXT=AddNewTorrentDialog]</legend>
                <table style="margin: auto;">
                    <tbody>
                        <tr>
                            <td>
                                <label for="autoTMM">QBT_TR(Torrent Management Mode:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                            </td>
                            <td>
                                <select id="autoTMM" name="autoTMM" onchange="qBittorrent.Download.changeTMM(this)">
                                    <option selected value="false">QBT_TR(Manual)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                    <option value="true">QBT_TR(Automatic)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="savepath">QBT_TR(Save files to location:)QBT_TR[CONTEXT=HttpServer]</label>
                            </td>
                            <td>
                                <input type="text" id="savepath" name="savepath" class="pathDirectory" style="width: 16em;">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="rename">QBT_TR(Rename torrent)QBT_TR[CONTEXT=HttpServer]</label>
                            </td>
                            <td>
                                <input type="text" id="rename" name="rename" style="width: 16em;">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label id="categoryLabel" for="categorySelect">QBT_TR(Category:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                            </td>
                            <td>
                                <div class="select-watched-folder-editable">
                                    <select id="categorySelect" onchange="qBittorrent.Download.changeCategorySelect(this)">
                                        <option selected value="\other"></option>
                                    </select>
                                    <input type="text" name="category" aria-labelledby="categoryLabel">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="startTorrent">QBT_TR(Start torrent)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                            </td>
                            <td>
                                <input type="hidden" id="startTorrentHidden" name="stopped">
                                <input type="checkbox" id="startTorrent">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="addToTopOfQueue">QBT_TR(Add to top of queue)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                            </td>
                            <td>
                                <input type="checkbox" id="addToTopOfQueue" name="addToTopOfQueue" value="true">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="stopCondition">QBT_TR(Stop condition:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                            </td>
                            <td>
                                <select id="stopCondition" name="stopCondition">
                                    <option selected value="None">QBT_TR(None)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                    <option value="MetadataReceived">QBT_TR(Metadata received)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                    <option value="FilesChecked">QBT_TR(Files checked)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="skip_checking">QBT_TR(Skip hash check)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                            </td>
                            <td>
                                <input type="checkbox" id="skip_checking" name="skip_checking" value="true">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="contentLayout">QBT_TR(Content layout:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
                            </td>
                            <td>
                                <select id="contentLayout" name="contentLayout">
                                    <option selected value="Original">QBT_TR(Original)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                    <option value="Subfolder">QBT_TR(Create subfolder)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                    <option value="NoSubfolder">QBT_TR(Don't create subfolder)QBT_TR[CONTEXT=AddNewTorrentDialog]</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="sequentialDownload">QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget]</label>
                            </td>
                            <td>
                                <input type="checkbox" id="sequentialDownload" name="sequentialDownload" value="true">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="firstLastPiecePrio">QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget]</label>
                            </td>
                            <td>
                                <input type="checkbox" id="firstLastPiecePrio" name="firstLastPiecePrio" value="true">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="dlLimitText">QBT_TR(Limit download rate)QBT_TR[CONTEXT=HttpServer]</label>
                            </td>
                            <td>
                                <input type="hidden" id="dlLimitHidden" name="dlLimit">
                                <input type="text" id="dlLimitText" style="width: 16em;" placeholder="KiB/s">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label for="upLimitText">QBT_TR(Limit upload rate)QBT_TR[CONTEXT=HttpServer]</label>
                            </td>
                            <td>
                                <input type="hidden" id="upLimitHidden" name="upLimit">
                                <input type="text" id="upLimitText" style="width: 16em;" placeholder="KiB/s">
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div id="submitbutton" style="margin-top: 12px; text-align: center;">
                    <button type="submit" id="submitButton">QBT_TR(Download)QBT_TR[CONTEXT=downloadFromURL]</button>
                </div>
            </fieldset>
        </div>
    </form>
    <div id="download_spinner" class="mochaSpinner"></div>
</body>

</html>
